<!--
  用户管理页面
-->
<template>
  <div class="leave-form">
    <Form ref="formInline" :label-width="70" :model="leaveInfo" :rules="leaveInfoRule">
      <FormItem label="请假事由">
        <Input  v-model="leaveInfo.reason" :disabled="disabled" :maxlength="50" placeholder="请填写50字以内的请假事由"></Input>
      </FormItem>
      <FormItem label="请假类型">
        <Select v-model="leaveInfo.type" placeholder="请假类型" :disabled="disabled">
          <Option value="1">事假</Option>
          <Option value="2">病假</Option>
          <Option value="3">年假</Option>
        </Select>
      </FormItem>
      <FormItem label="请假时间">
        <DatePicker type="datetimerange" @on-change="changeDate" :disabled="disabled" :value="[this.leaveInfo.startTime,this.leaveInfo.endTime]" placeholder="请选择请假时间"
                    style="width: 300px"></DatePicker>
      </FormItem>
      <FormItem label="请假天数">
        <InputNumber v-model="leaveInfo.days" :disabled="disabled" placeholder="请假天数"></InputNumber>
      </FormItem>
      <FormItem label="详细描述">
        <Input type="textarea" v-model="leaveInfo.details" :disabled="disabled" :rows="3" placeholder="请填写200字以内的描述" :maxlength="200"></Input>
      </FormItem>
    </Form>
  </div>

</template>

<script>
import * as API from "@/api/sys-leave.js";

export default {
  name: "leave-form",
  components: {},
  props: {
    businessId: {
      type: String,
      default:""
    },
    disabled: {
      type: Boolean,
      default:false
    },
  },
  data() {
    return {
      leaveInfo: {
        type: "",
        startTime: "",
        endTime: 1,
        reason: "",
        details: "",
        days: 0,
      },
      leaveInfoRule: {}
    };
  },
  methods: {
    //保存或提交请假信息
    saveLeave() {
      let params = Object.assign({}, this.leaveInfo)
      params.saveStatus = 2
      API.saveLeaveInfo(params).then(res => {
        if (res.code === "0") {
          this.$Message.success(res.msg);
          this.closeModal()
          this.serachTableData()
        } else {
          this.$Message.error(res.msg);
        }
      })
    },
    //选择请假时间
    changeDate(dateArr) {
      this.leaveInfo.startTime = dateArr[0]
      this.leaveInfo.endTime = dateArr[1]
    },

    //获取请假信息
    getLeaveInfo(){
      API.getLeaveData({id:this.businessId}).then(res=>{
        if (res.code==='0'){
          let params = Object.assign({},res.data)
          params.days = parseInt(params.days)
          this.leaveInfo = params
          this.$emit("infoBack",params)
        }
      })
    }

  },
  created() {
    if (this.businessId){
      this.getLeaveInfo()
    }
  },
};
</script>
<style lang="less" scoped>
.leave-form {
}
</style>
